<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title>Ajax Test</title>
<style type="text/css">
.errorMessage {
	color: red;
}
</style>
<script language="javascript">


function cost_addRow(tableid,button,value)
{
	alert("called");
	button.disabled = "true";
	var table = document.getElementById(tableid);
	var rowcount = table.rows.length;
	var colcount = table.rows[0].cells.length;
	colcount+=1; // provision for 1 more column for save buttons
	var row = table.insertRow(rowcount);
	for (var i=0;i<colcount;i++)
	{
		var newcell = row.insertCell(i);
		var id=tableid+rowcount+i;
		switch (i)
		{
			case 0:
				newcell.innerHTML='<s:textfield id="'+id+'" name="perform.standard" value="'+value+'" size="20" theme="simple"/>';
				break;
			case 1:
				newcell.innerHTML='<s:textfield id="'+id+'" name="perform.marks" value="'+value+'" size="10" theme="simple"/>';
				break;
			case 2:
				newcell.innerHTML='<input id="'+id+'" type="button" value="Save">';
				newcell.childNodes[0].onclick=new Function("saveRow('"+tableid+"','"+rowcount+"','"+colcount+"')");
				break;
		}
	}	

}

function saveRow(tableid,row_no,total_cells)
{
	var table = document.getElementById(tableid);

	for (var i=0;i<total_cells;i++)
	{
		var id = tableid+row_no+i;
		var element = document.getElementById(id);
		element.disabled="true";
	}

	var button = document.getElementById("performance_button");
	button.disabled = "";
}
</script>

</head>
<body>
	<table>
		<s:form action="output">
			<tr>
				<td><s:textfield name="stud.name" label="student name"
						size="20" /> <s:select label="student sex code" name="stud.sex"
						list="{'Male', 'Female'}" />
				</td>
			</tr>
			<tr>
				<td>
					<table id="performance">
						<tr>
							<td>Standard</td>
							<td>Marks</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td></td>
				<td><input id="performance_button" type="button" value="Add"
					onclick="cost_addRow('performance',this,'' )" /></td>
			</tr>
			<tr>
				<td></td>
			</tr>

			<tr>
				<td></td>
				<td><s:submit value="Save" theme="simple" />
				</td>
			</tr>
		</s:form>
	</table>

</body>
</html>
